<?php 
ob_start();
session_cache_expire(999999999);
if(!isset($_SESSION)){ 
	session_start(); 
} 
if(!isset($_SESSION['user'])){
	header( 'Location: login.php' );
}else{
	$username = $_SESSION['fullname'];
	$id_employee = $_SESSION['IDEmployee'];
}
$_SESSION['thongbao_chamcong']='';
$idpro = $_REQUEST['id'];
$page=1;
$tab = isset ( $_REQUEST["tab"] ) ? intval ( $_REQUEST["tab"] ) : 1;
if(isset($_REQUEST['addnewerror'])){
	$mlisttest=$_SESSION['mangtester'];
	$title=addslashes($_REQUEST['titleerror']);
	if(!empty($title)){
		$content = addslashes($_REQUEST['ncontent']);
		$soluong=0;
		include '../../operations/connection.php';	
		set_time_limit(0);
		$sql1="select pr_nforder from pr_newfunction_order  where pr_idproject='".$idpro."'";
		$msoluong=mysql_query($sql1);
		while($row=mysql_fetch_array($msoluong)){
			$soluong=$row['pr_nforder']+1;
		}
		$idnf=$_SERVER['REQUEST_TIME'];
		$sql="insert into pr_newfunction (nfid,pr_idproject,nf_order,nf_title,nf_content,nf_createdate,nf_employee,nf_employee_name) 
		value ('".$idnf."','".$idpro."',".$soluong.",'".$title."','".$content."',now(),'".$_SESSION['IDEmployee']."','".$_SESSION['fullname']."')";
		mysql_query($sql);
		if($soluong==0){
			$sql2="insert into pr_newfunction_order (pr_idproject,pr_nforder) value ('".$idpro."',".$soluong.")";
			mysql_query($sql2);
		}else{
			$sql3="update pr_newfunction_order set pr_nforder=".$soluong." where  pr_idproject='".$idpro."'";
			mysql_query($sql3);
		}
		mysql_close($connection);
		if($mlisttest!=''){
			$addressbrowser = $_SERVER['SERVER_NAME'];
			$temp = explode(".", $addressbrowser);
			$lang=$_SESSION['lang'];
			if($lang==''){
				$lang='EN';
				$_SESSION['lang']="EN";
			}
			$url = 'http://1.234.53.52/mail/mail_newfunction.php';
			$fields = array(
									//'company' => urlencode('elitech'),
									'company' => urlencode($temp[0]),
									'lang' => urlencode($lang),
									'dfrom' => urlencode($username),
									'listid' => urlencode($mlisttest),
									'idpro' =>  urlencode($idpro),
									'idnf' => urlencode($idnf),
									'trangthai' => urlencode($_SESSION['projectinfo']['trangthai']) ,
									'nguoiquanly' => urlencode($_SESSION['projectinfo']['nguoiquanly']) ,
									'ngaybatdau' => urlencode($_SESSION['projectinfo']['ngaybatdau']),
									'prname' => urlencode($_SESSION['projectinfo']['namepro_temp']),
									'prview' => urlencode($_SESSION['projectinfo']['idviewpro']),
									'nguoiguidi' => urlencode($id_employee)
							);
			/*$url = 'http://localhost/mail/mail_newfunction.php';
			$fields = array(
									'company' => urlencode('elitech'),
									'lang' => urlencode($lang),
									'dfrom' => urlencode($username),
									'listid' => urlencode($mlisttest),
									'idpro' =>  urlencode($idpro),
									'idnf' => urlencode($idnf),
									'trangthai' => urlencode($_SESSION['projectinfo']['trangthai']) ,
									'nguoiquanly' => urlencode($_SESSION['projectinfo']['nguoiquanly']) ,
									'ngaybatdau' => urlencode($_SESSION['projectinfo']['ngaybatdau']),
									'prname' => urlencode($_SESSION['projectinfo']['namepro_temp']),
									'prview' => urlencode($_SESSION['projectinfo']['idviewpro']),
									'nguoiguidi' => urlencode($id_employee)
							);*/
			foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
			rtrim($fields_string, '&');
			$ch = curl_init();
			curl_setopt($ch,CURLOPT_URL, $url);
			curl_setopt($ch,CURLOPT_POST, count($fields));
			curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
			$result = curl_exec($ch);
			curl_close($ch);
			$_SESSION['thongbao_chamcong']=$l_sending_mail_has_been_made;
		}
	}
}else if(isset($_REQUEST['update'])){
	$page = isset ( $_REQUEST["page"] ) ? intval ( $_REQUEST["page"] ) : 1;
	$title=addslashes($_REQUEST['titleerror']);
	$content = addslashes($_REQUEST['ncontent']);
	$idnf=$_REQUEST['idtestproject'];
	if(!empty($idnf)){
		$sql="update pr_newfunction set nf_title = '".$title."',nf_content = '".$content."',nf_createdate=now() where nfid='".$idnf."'";
		include '../../operations/connection.php';	
		set_time_limit(0);
		mysql_query($sql);
		mysql_close($connection);
	}
}
header("Location: ../../project_admin.php?content=admin/project/project_feature.php&id=$idpro&tab=$tab&page=$page");
?>